package leetcode;

public class Leetcode221 {
    public int maximalSquare(char[][] matrix) {
        //求每个正方形最大边长
        int rows = matrix.length;
        int cols = matrix[0].length;
        int max = 1;
        int[][] dp = new int[rows+1][cols+1];
        for(int i = 1;i<=rows;i++){
            for(int j = 1;j<cols;j++){
                if(matrix[i-1][j-1]=='1'){
                    dp[i][j] = Math.min(dp[i-1][j-1],Math.min(dp[i-1][j],dp[i][j-1]))+1;
                    max = Math.max(max,dp[i][j]);
                }
            }
        }
        return max*max;
    }
}
